package com.UI
{
	import com.*;
	import com.Engine.*;
	import com.Packet.*;
	
	import fl.text.TLFTextField;
	
	import flash.display.*;
	import flash.display.InteractiveObject;
	import flash.display.Loader;
	import flash.display.MovieClip;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.*;
	import flash.events.Event;
	import flash.events.KeyboardEvent;
	import flash.events.MouseEvent;
	import flash.events.TextEvent;
	import flash.external.*;
	import flash.filters.*;
	import flash.geom.*;
	import flash.net.*;
	import flash.system.*;
	import flash.text.*;
	import flash.text.TextField;
	import flash.text.TextFieldType;
	import flash.text.TextFormat;
	import flash.text.engine.ElementFormat;
	import flash.ui.*;
	import flash.ui.Keyboard;
	import flash.utils.*;
	import flash.utils.getDefinitionByName;
	
	import flashx.textLayout.edit.EditManager;
	import flashx.textLayout.edit.SelectionManager;
	import flashx.textLayout.edit.SelectionState;
	import flashx.textLayout.elements.FlowElement;
	import flashx.textLayout.elements.ParagraphElement;
	import flashx.textLayout.elements.SpanElement;
	import flashx.textLayout.elements.TextFlow;
	
	import org.aswing.*;
	import org.aswing.border.*;
	import org.aswing.border.EmptyBorder;
	import org.aswing.colorchooser.*;
	import org.aswing.ext.*;
	import org.aswing.geom.*;
	import org.aswing.plaf.*;
	import org.aswing.skinbuilder.SkinProgressBarBackground;
	import org.aswing.skinbuilder.SkinProgressBarForeground;
	import org.aswing.skinbuilder.SkinScrollBarBackground;
	import org.aswing.skinbuilder.SkinScrollBarThumb;
	import org.aswing.skinbuilder.SkinScrollBarUI;
	
	public class FrameMining  extends JFrame
	{
		//members define
		private var panelProgress:PanelProgress;
		private var labelInfo:JLabel;
		
		public function FrameMining()
		{
			super();
			setDragable(false);
			setClosable(false);
			setResizable(false);
			setTitleBar(null);
			setBorder(new EmptyBorder());
			this.setBackgroundDecorator(new SolidBackground(new ASColor(0,0)));
			
			//component creation
			setSize(new IntDimension(229, 34));
			setPreferredSize(new IntDimension(229, 34));
			var layout0:EmptyLayout = new EmptyLayout();
			getContentPane().setLayout(layout0);
			
			panelProgress = new PanelProgress();
			panelProgress.setLocation(new IntPoint(22, 15));
			panelProgress.setSize(new IntDimension(183, 11));
			panelProgress.setPreferredSize(new IntDimension(183, 11));
			
			labelInfo = new JLabel();
			labelInfo.setLocation(new IntPoint(22, 0));
			labelInfo.setSize(new IntDimension(183, 15));
			labelInfo.setPreferredSize(new IntDimension(183, 15));
			labelInfo.setText("挖矿中...");
			
			//component layoution
			getContentPane().append(panelProgress);
			getContentPane().append(labelInfo);
			
			var font:ASFont = null;//new ASFont("宋体", 14, true, false, false, false);
			var filter:GlowFilter = null;
			font = new ASFont("宋体", 12, false, false, false, false);
			filter = new GlowFilter(0x000000, 1, 2, 2, 10);
			labelInfo.setForeground(ASColor.YELLOW);
			labelInfo.setFont(font);
			labelInfo.setTextFilters(new Array(filter));
			
			//setBackgroundDecorator(new AssetBackground(Client.getUIElement("img_mining_bg") as DisplayObject));
			
			var img_copy_bg:AssetBackground  = new AssetBackground(Client.getUIElement("img_mining_bg") as DisplayObject);
			var img_char_background:DisplayObject = img_copy_bg.getDisplay(null);
			setBackgroundDecorator(img_copy_bg);
			setSizeWH(img_char_background.width,img_char_background.height);
			setLocationXY((Engine.W - width)/2,(Engine.H - height)/2);
			
			panelProgress.setBackgroundDecorator(null);
			panelProgress.setResource("img_mining_progress_bg");
			panelProgress.setMaxValue(5000);
		}
		public static var _timerUpdate:Timer = null;
		public function reset():void
		{
			panelProgress.setValue(0);
			
			if(_timerUpdate == null)
			{
				_timerUpdate = new Timer(50);
				_timerUpdate.addEventListener(TimerEvent.TIMER,onTimerUpdate);
			}
			if(_timerUpdate.running)
			{
				_timerUpdate.stop();
				_timerUpdate.reset();
			}
			_timerUpdate.start();
			updateCount = 0;
			
		}
		private var updateCount:int = 0;
		private function onTimerUpdate(e:TimerEvent):void
		{
			updateCount++;
			//panelProgress.setValue(updateCount * 10);
			panelProgress.updateValue(updateCount * 50,5000);
			if(updateCount >= 100)
			{
				_timerUpdate.stop();
				Client.getInstance().sendPacketLogic(2000,[int(0)]);
				FrameMining.hide();
				updateCount = 0;
			}
			var count:int = updateCount % 4;
			if(count == 0)labelInfo.setText("挖矿中");
			if(count == 1)labelInfo.setText("挖矿中.");
			if(count == 2)labelInfo.setText("挖矿中..");
			if(count == 3)labelInfo.setText("挖矿中...");
		}
		
		public static function phMining_2000(e:PacketEvent):void
		{
			var msg:Array = e.data as Array;
			trace("phMining_2000", msg);
			var nIndex:uint = 0;
			
			FrameMining.show();
		}
		
		public static var _frame:FrameMining = null;
		public static function show():void
		{
			if(isShowing())
			{
				_frame.hide();
				return;
			}
			if(_frame == null)
			{
				_frame = new FrameMining();
				PanelMainHelp.getInstance().addChild(_frame);
			}
			_frame.show();
			PanelMainHelp.getInstance().bringToTop(_frame);
			_frame.reset();
			
		}
		public static function hide():void
		{
			if(isShowing())_frame.hide();
		}
		public static function isShowing():Boolean
		{
			return(_frame != null&& _frame.isShowing());
		}
	}
}